// pages/index/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    latitude: null,
    longitude: null,
    circles: [{
      latitude: null,
      longitude: null,
      color: '#1296db',
      radius: 10,
    }],
    markers: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getLOcation();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  getLOcation() {
    let that = this
    wx.getLocation({
      type: 'wgs84',
      success: function(res) {
        let latitude = res.latitude
        let longitude = res.longitude
        that.setData({
          latitude: latitude,
          longitude: longitude,
        })
        that.addMarksList();
      }
    })
  },
  addMarksList() {
    this.setData({
      markers: [{
          iconPath: "/image/location.png",
          id: 0,
          latitude: 26.605915,
          longitude: 106.728306,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店1号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        },
        {
          iconPath: "/image/location.png",
          id: 1,
          latitude: 26.596638,
          longitude: 106.719053,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店2号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }

        }, {
          iconPath: "/image/location.png",
          id: 2,
          latitude: 26.598173,
          longitude: 106.715104,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店3号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 3,
          latitude: 26.605915,
          longitude: 106.728306,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店4号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 4,
          latitude: 26.604312,
          longitude: 106.720855,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店5号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 5,
          latitude: 26.602739,
          longitude: 106.723902,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店6号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 6,
          latitude: 26.599209,
          longitude: 106.717937,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店7号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 7,
          latitude: 26.595103,
          longitude: 106.716435,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店8号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 8,
          latitude: 26.600821,
          longitude: 106.715834,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店9号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }, {
          iconPath: "/image/location.png",
          id: 9,
          latitude: 26.597252,
          longitude: 106.722228,
          width: 30,
          height: 30,
          callout: {
            content: '烟草专卖店10号店',
            padding: 8,
            borderRadius: 4,
            bgColor: '#1296db',
            color: '#f8f8f8',
          }
        }
      ],
    })
  },
  tapmarkertap(e) {
    console.log(e);

  },
  tapcallouttap(e) {
    console.log(e);
    let markers = this.data.markers
    let markerId = e.markerId
    let latitude = markers[markerId].latitude
    let longitude = markers[markerId].longitude
    let name = markers[markerId].callout.content
    this.openLocation(latitude, longitude, name);
  },
  openLocation(latitude, longitude, name) {
    wx.openLocation({
      latitude: latitude,
      longitude: longitude,
      name: name
    })
  }
})